//
//  FirstCollectionViewCell.m
//  土巴兔
//
//  Created by 千锋 on 16/1/4.
//  Copyright (c) 2016年 IOS1503薛凯. All rights reserved.
//

#import "FirstCollectionViewCell.h"
#import "Default.h"
#import "UIImageView+WebCache.h"
@implementation FirstCollectionViewCell
- (instancetype)initWithFrame:(CGRect)frame{
    if (self=[super initWithFrame:frame]) {
        [self createUI];
    }
    return self;
}
- (instancetype)init{
    if(self=[super init]){
        [self createUI];
    }
    return self;
}
- (void)createUI{
    _imageview=[[UIImageView alloc] init];
//    WithFrame:CGRectMake(0, 0, self.contentView.bounds.size.width, self.contentView.bounds.size.height-20)
    _imageview.frame=self.contentView.bounds;
//    CGRectMake(0, 0, self.contentView.bounds.size.width,self.contentView.bounds.size.height-20);
    [self.contentView addSubview:_imageview];
    _label=[[UILabel alloc] init];
//    WithFrame:CGRectMake(8, self.contentView.bounds.size.height-20, self.contentView.bounds.size.width, 20)
    _label.frame=CGRectMake(0,_imageview.frame.size.height-20, _imageview.frame.size.width, 20);
    _label.font=[UIFont systemFontOfSize:13];
    _label.numberOfLines=1;
    _label.backgroundColor=[UIColor lightGrayColor];
    [self.contentView addSubview:_label];
}
- (void)relayoutUIWithModel:(FirstModel*)model{
    [_imageview sd_setImageWithURL:[NSURL URLWithString:((SecondModel*)(model.info)[0]).filename]];
    
    [_label setText:model.title];
    CGFloat weidth=(DEVICEWIDTH-10)/2;
    SecondModel* secmodel=model.info[0];
    CGFloat height=[secmodel.height floatValue]*weidth/[secmodel.width floatValue];
    _imageview.frame=CGRectMake(0, 0, weidth, height);
//    _label.frame=CGRectMake(0,_imageview.frame.size.height, _imageview.frame.size.width, 40);
    _label.frame=CGRectMake(0,_imageview.frame.size.height-20, _imageview.frame.size.width, 20);
    _label.textAlignment=NSTextAlignmentCenter;
}
@end
